import { ApiCall } from "tsrpc";
import { ReqRoomList, ResRoomList } from "../../../tsrpc/shared/protocols/hall/PtlRoomList";
import { RoomInfo } from "../../../tsrpc/shared/type/RoomInfo";
import { hs } from "../../../HallServer";

export default async function (call: ApiCall<ReqRoomList, ResRoomList>) {

    const rooms:RoomInfo[] = [];
    for (const room of hs.HallModel.rooms.values()) {
        rooms.push({
            roomId: room.RoomModel.roomId,
            currentNum: room.RoomModel.users.size,
            maxNum: room.RoomModel.maxNum,
            roomState: room.RoomModel.state,
            roomName: room.RoomModel.roomName,
            roomServerAddr: room.RoomModel.roomServerAddr
        }
        )
    }

    call.succ({ rooms:rooms});
}